package com.libraries.image.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.libraries.helper.ImgHelper;
import com.example.libraries.R;
import com.facebook.drawee.view.SimpleDraweeView;
public class ImageGalleryAdapter  extends BaseAdapter {
	private ArrayList<String> lGalleryImgs;
	private LayoutInflater mInflater;
	private int currIndex;
	public ImageGalleryAdapter(Context context, ArrayList<String> lGalleryImgs) {
		this.lGalleryImgs =lGalleryImgs;
		this.mInflater = LayoutInflater.from(context);
	}
	
    public void notifyDataSetChanged(ArrayList<String> lGalleryImgs) {
    	this.lGalleryImgs=lGalleryImgs;
    	notifyDataSetChanged();
    };
    
   public void setCurrIndex(int currIndex) {
		this.currIndex = currIndex;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return lGalleryImgs.size();
	}

	@Override
	public Object getItem(int position) {
		return lGalleryImgs.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		SimpleDraweeView iv_img;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.image_gallery_item, null);
			iv_img = (SimpleDraweeView) convertView.findViewById(R.id.iv_img);
			convertView.setTag(iv_img);
		} else {
			iv_img = (SimpleDraweeView) convertView.getTag();
		}
		if (position==currIndex) {
			iv_img.setBackgroundResource(R.drawable.d_galleryimg_shape);
		}
		else {
			iv_img.setBackgroundColor(Color.TRANSPARENT);
		}
		String imgPath = (String) getItem(position);
		ImgHelper.loadFileByFresco(iv_img, imgPath,null);
		return convertView;
	}

}
